import openai

# Initialize the OpenAI client
openai.api_key = "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"

while True:
    # Read the next prompt from the user
    user_input = input("You: ")

    # Exit the loop if the user types 'exit'
    if user_input.lower() == 'exit':
        print("Exiting the chat.")
        break

    # Check if the user wants to generate an image
    if user_input.lower().startswith("generate image"):
        image_prompt = user_input[len("generate image"):].strip()

        try:
            # Generate the image
            image_response = openai.Image.create(prompt=image_prompt)
            image_url = image_response['data'][0]['url']
            print("Image URL:", image_url)
        except Exception as e:
            print("Error generating image:", e)
    else:
        print("Please start your request with 'generate image' to create an image.")
